package com.cn.wanxi.service.impl;

import com.cn.wanxi.entity.UserEntity;
import com.cn.wanxi.mapper.UserMapper;
import com.cn.wanxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public String login(UserEntity userEntity) {
        if (userEntity.getCode().equals(userEntity.getSessionCode())) {
//            UserDao userDao = new UserImpl();
            UserEntity entity = userMapper.findByUsernameAndPassword(userEntity);
            return entity == null ? "error" : "success";
        }
        return "error-code";
    }

    @Override
    public List<UserEntity> findAll(UserEntity userEntity) {
        return userMapper.findAll(userEntity);
    }

    @Override
    public int getCount(UserEntity userEntity) {
        return userMapper.getCount(userEntity);
    }

    @Override
    public UserEntity findById(int id) {

        return userMapper.findById(id);
    }
}
